//https://www.microsoftstore.com.cn/
const https = require('https');
const $ = require('cheerio');
function filterData(data) {
  // console.log(data);
  var items = $(data).find('.listContainerInner li');
  // console.log(items.length);
  var result = [];
  $(items).each((index, item) => {
    let $item = $(item);
    var param = {
      url: $item.find('img').attr('data-src'),
      name: $item.find('.name h4').text().replace(/\n|\t/g, ''),
      price: $item.find('.price strong').text()
    }
    result.push(param);

  })
  console.log(result);
}

var app = https.request({
  protocol: 'https:',
  hostname: 'www.microsoftstore.com.cn',
  port: 443,
  method: 'GET'
}, (res) => {

  var rawdata = '';
  res.on('data', (chunk) => {
    rawdata += chunk;
  })


  res.on('end', () => {
    // console.log(rawdata)
    filterData(rawdata);
  })

})

app.end()